﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IceCS.Img2Base64
{
    public class Core
    {
        /// <summary>
        /// 把图片流转换文本为Base64字符串
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static string ConvertImgToBase64Text(Stream stream)
        {
            stream.Seek(0, SeekOrigin.Begin);
            using (var br = new BinaryReader(stream))
            {
                var str = Convert.ToBase64String(br.ReadBytes((int)stream.Length));
                return str;
            }
        }
        /// <summary>
        /// 把Base64字符串转换为图片流
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static Stream ConvertBase64TextToImg(string text)
        {
            var bytes = Convert.FromBase64String(text);
            var ms = new MemoryStream(bytes);
            return ms;
        }
    }
}
